/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pbl;

import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class PersonClient {

    public static void main(String[] args) throws Exception {

        InetAddress serverAddress = InetAddress.getByName("localhost");
        int serverPort = 7897;

        Socket socket = new Socket(serverAddress, serverPort);
        OutputStream os = socket.getOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(os);

        
        
        oos.writeObject( new Person("dgg", 43));
        


        //socket.close();
    }


public static void testClient() throws Exception {
            InetAddress serverAddress = InetAddress.getByName("localhost");
	    int serverPort = 8000;
	    Socket socket = new Socket( serverAddress, serverPort );
	    OutputStream os = socket.getOutputStream();
	    ObjectOutputStream oos = new ObjectOutputStream( os );
	    Boolean boo = true;
            oos.writeObject( new Person("Bjarne Pedersen", 13) );
            oos.flush();
            oos.close();
            socket.close();
            
        }
        
	public static void addPerson(Person person) throws Exception
	{
            InetAddress serverAddress = InetAddress.getByName("localhost");
	    int serverPort = 6000;
	    Socket socket = new Socket( serverAddress, serverPort );
	    OutputStream os = socket.getOutputStream();
	    ObjectOutputStream oos = new ObjectOutputStream( os );
	    
            oos.writeObject( new Integer(33));
	    /*oos.writeInt( 1 );
	    oos.writeObject( person );
	    oos.flush();
	    socket.close();*/
    }
	
	public static Person fetchPerson(int index) throws Exception 
	{	
            InetAddress serverAddress = InetAddress.getByName("localhost");
	    int serverPort = 6000;
	    Socket socket = new Socket( serverAddress, serverPort );
	    OutputStream os = socket.getOutputStream();
	    ObjectOutputStream oos = new ObjectOutputStream( os );
	    InputStream is = socket.getInputStream();
	    ObjectInputStream ois = new ObjectInputStream( is );
	    
            oos.writeInt( 2 );
            Person person = (Person) ois.readObject();
            socket.close();
            return person;
	}
	
}
